package com.heima.article.config.xxl_job;


import com.heima.article.controller.v1.AutomaticController;
import com.heima.article.feign.WemediaFeign;
import com.heima.model.common.dtos.ResponseResult;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Log4j2
public class WeMediaNewsAutoScanJob {

    @Autowired
    AutomaticController automaticController;  //自动审核远程调用

    @Autowired
    WemediaFeign wemediaFeign;   //自媒体远程调用

    /**
     * 每天0点执行一次
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("wemediaAutoScanJob") //@XxlJob("wemediaAutoScanJob")`这个一定要与调度中心新建任务的JobHandler的值保持一致
    public ReturnT<String> hello(String param) throws Exception {
        log.info("自媒体文章审核调度任务开始执行....");
        ResponseResult<List<Integer>> allByStatus = wemediaFeign.findAllByStatus();
        List<Integer> list = allByStatus.getData();
        if(null!=list && !list.isEmpty()){
                for (Integer id : list) {
                automaticController.autoScanByMediaNewsId(id);
            }
        }
        log.info("自媒体文章审核调度任务执行结束....");
        return ReturnT.SUCCESS;
    }

}